package SGEngine

import (
	"math"
)

var (
	Vector3Zero = Vector3{0, 0, 0}
	Vector3One  = Vector3{1, 1, 1}
	Vector2One  = Vector2{1, 1}
)

//Vector//
///////////////////////////////////////////////////////////////
type Vector3 struct {
	X float32
	Y float32
	Z float32
}

func (v *Vector3) Length() float32 {
	return v.X*v.X + v.Y*v.Y + v.Z*v.Z
}

func (v *Vector3) Distance(v3 Vector3) float64 {
	H := math.Abs(float64(v.Z) - float64(v3.Z))

	d2d := math.Sqrt(math.Pow(float64(v.X-v3.X), 2) + math.Pow(float64(v.Y-v3.Y), 2))

	d3d := math.Sqrt(math.Pow(H, 2) + math.Pow(d2d, 2))
	return d3d
}

func (v *Vector3) DivNum(num float32) Vector3 {
	return NewVector3(v.X/num, v.Y/num, v.Z/num)
}

func (v *Vector3) Sub(v3 Vector3) Vector3 {
	return Vector3{v.X - v3.X, v.Y - v3.Y, v.Z - v3.Z}
}

func (v *Vector3) SubNum(num float32) Vector3 {

	return NewVector3(v.X*num, v.Y*num, v.Z*num)
}

func (v *Vector3) AddMe(v3 Vector3) {
	v.X += v3.X
	v.Y += v3.Y
	v.Z += v3.Z
}

func (v *Vector3) Normalize() Vector3 {
	len := v.Length()
	len = float32(math.Sqrt(float64(len)))
	if len == 0 {
		return Vector3Zero
	}
	v.X /= len
	v.Y /= len
	v.Z /= len
	return *v
}

//叉乘
func (v *Vector3) Cross(vec Vector3) Vector3 {

	return NewVector3(v.Y*vec.Z-v.Z*vec.Y, v.Z*vec.X-v.X*vec.Z, v.X*vec.Y-v.Y*vec.X)
}

//普通乘
func (v *Vector3) Multiply(vec Vector3) {
	v.X *= vec.X
	v.Y *= vec.Y
	v.Z *= vec.Z
}
func NewVector3(_X, _Y, _Z float32) Vector3 {
	return Vector3{_X, _Y, _Z}
}

type Vector2 struct {
	X float32
	Y float32
}

func NewVector2(_X, _Y float32) Vector2 {
	return Vector2{_X, _Y}
}

type Vector4 struct {
	X float32
	Y float32
	Z float32
	W float32
}

//Rect//////////////////////////////////////////////////
type Rect struct {
	MinX float64
	MinY float64
	MaxX float64
	MaxY float64
}

type RectDir struct {
	Left   float32
	Right  float32
	Top    float32
	Bottom float32
}
